//
//  PhotoImgCollCell.swift
//  DMCamera
//
//  Created by 李浩 on 2017/8/3.
//  Copyright © 2017年 李浩. All rights reserved.
//

import UIKit
import Photos

class PhotoImgCollCell: UICollectionViewCell {
   
    var imgV: UIImageView!
    override init(frame: CGRect) {
        super.init(frame: frame)
        imgV = UIImageView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))
        imgV.backgroundColor = UIColor.red
        imgV.clipsToBounds = true
        imgV.contentMode = .scaleAspectFill
        contentView.addSubview(imgV)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func configView(image: PHAsset) {
        DispatchQueue.global().async {
            PHImageManager.default().requestImage(for: image, targetSize: CGSize(width: 150, height: 150), contentMode: .aspectFit, options: nil) { (img, dic) in
                if (img != nil) {
                    DispatchQueue.main.async {
                        self.imgV.image = img
                    }
                }
            }
            
        }
    }
    
}
